﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hi_Baidu.Packet.InPacket
{
    class RedirectAddFriendPacket : BaseInPackage
    {
        public RedirectAddFriendPacket(InPackage inpackage) : base(inpackage)
        {
        }

        public override void InitPackage()
        {
            int Offset = 0;
            //用户名长度
            byte[] UsernameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, UsernameLength, 0, 4);
            Offset += 4;
            //用户名
            byte[] Username = new byte[BitConverter.ToInt32(UsernameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Username, 0, Username.Length);
            Offset += Username.Length;
            //分组ID
            byte[] ItemId = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, ItemId, 0, 4);
            Offset += 4;
            //好友用户名长度
            byte[] FriendNameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, FriendNameLength, 0, 4);
            Offset += 4;
            //好友用户名
            byte[] FriendName = new byte[BitConverter.ToInt32(FriendNameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, FriendName, 0, FriendName.Length);
            Offset += FriendName.Length;
            //会话ID长度
            byte[] SessionLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, SessionLength, 0, 4);
            Offset += 4;
            //会话ID
            byte[] Session = new byte[BitConverter.ToInt32(SessionLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Session, 0, Session.Length);
            Offset += Session.Length;
            this.DIC_CONTENT.Add("USERNAME", Username);
            this.DIC_CONTENT.Add("ITEMID", ItemId);
            this.DIC_CONTENT.Add("FriendName", FriendName);
            this.DIC_CONTENT.Add("SESSION", Session);
        }

        /// <summary>
        ///     获得分组ID
        /// </summary>
        /// <returns></returns>
        public String GetItemId()
        {
            return Encoding.Default.GetString(this.DIC_CONTENT["ITEMID"]).Replace("*@^@*", "");
        }
    }
}
